<%@ Page  Language="C#" MasterPageFile="~/MasterPages/Core.Master" AutoEventWireup="true"
    CodeBehind="ProjectsList.aspx.cs" Title="<% $Resources:PageTitle %>" Inherits="Pap.Web.Modules.Administration.Views.ProjectsList" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type="text/javascript">
        function Prepare(grid, toolbar, rowIndex, record) {
            var count = Ext.getCmp('gvProjects').getStore().getCount();
            var firstButton = toolbar.items.get(0);
            if (rowIndex != count - 1) {
                firstButton.setDisabled(true);
            }
        }

        function gvProjects_Command(command) {
            if (command == "Delete") {
                Ext.Msg.confirm('<asp:Literal runat="server" Text="<%$ Resources:MBConfirm%>" />', '<asp:Literal runat="server" Text="<%$ Resources:MBSureDelete %>" />', Pap.DeleteProject);
            }

        }
    </script>

    <ext:Store ID="projectsStore" runat="server">
        <Reader>
            <ext:JsonReader ReaderID="ProjectID">
                <Fields>
                    <ext:RecordField Name="ProjectID" />
                    <ext:RecordField Name="ProjectName" />
                    <ext:RecordField Name="ProfitPercent" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:FitLayout runat="server" IDMode="Static">
        <ext:FormPanel runat="server" Frame="false" Border="false" IDMode="Static">
            <Body>
                <ext:FitLayout runat="server">
                    <ext:GridPanel ID="gvProjects" runat="server" StoreID="projectsStore" Title="Projects List"
                        TrackMouseOver="True" StripeRows="True" IDMode="Static" AutoWidth="True" meta:resourcekey="gvProjectsResource1">
                        <ColumnModel>
                            <Columns>
                                <ext:Column Header="<%$ Resources:HeaderProjectName %>" DataIndex="ProjectName" />
                                <ext:Column Header="<%$ Resources:HeaderProfitPercent %>" DataIndex="ProfitPercent" />
                                <ext:CommandColumn Header="<%$ Resources:HeaderOperations %>" Width="110px" Fixed="True"
                                    Hideable="False">
                                    <Commands>
                                        <quadz:CoolitePermitGridCommand Icon="Delete" CommandName="Delete" IconCls="icon-delete"
                                            PermissionName="DeleteProject" HideAsDisabled="true">
                                            <ToolTip Text="<%$ Resources:CommandDeleteToolTip %>" />
                                        </quadz:CoolitePermitGridCommand>
                                        <ext:GridCommand Icon="NoteEdit" CommandName="Edit" IconCls="icon-noteedit">
                                            <ToolTip Text="<%$ Resources:CommandEditToolTip %>" />
                                        </ext:GridCommand>
                                    </Commands>
                                    <PrepareToolbar Fn="Prepare" />
                                </ext:CommandColumn>
                            </Columns>
                        </ColumnModel>
                        <BottomBar>
                            <ext:PagingToolbar ID="pagingBar" runat="server" StoreID="projectsStore" PageSize="15"
                                DisplayInfo="True" IDMode="Static" meta:resourcekey="pagingBarResource1" />
                        </BottomBar>
                        <AjaxEvents>
                            <Command OnEvent="gvProjects_Commad">
                                <ExtraParams>
                                    <ext:Parameter Name="CommandName" Value="command" Mode="Raw" Encode="False" />
                                    <ext:Parameter Name="ID" Value="record.data.ProjectID" Mode="Raw" Encode="False" />
                                </ExtraParams>
                            </Command>
                        </AjaxEvents>
                        <Listeners>
                            <Command Handler="gvProjects_Command(command);" />
                        </Listeners>
                    </ext:GridPanel>
                </ext:FitLayout>
            </Body>
        </ext:FormPanel>
    </ext:FitLayout>
</asp:Content>
